package com.zr.task.broadcast;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.RequiresPermission;
import com.zh.baselibrary.constant.BaseConstant;
import com.zh.baselibrary.model.BookModel;
import com.zh.baselibrary.model.TaskModel;
import com.zh.baselibrary.netutils.BaseResp;
import com.zh.baselibrary.rxjava.RxSubscribe;
import com.zh.baselibrary.utils.JsonUtils;
import com.zh.baselibrary.utils.LogUtils;
import com.zh.baselibrary.utils.PhoneUtil;
import com.zh.baselibrary.utils.ShareManager;
import com.zh.baselibrary.views.ToastView;
import com.zh.model.task.home.ClassCabinetBean;
import com.zh.model.task.home.CommitBean;
import com.zr.task.constant.Constant;
import com.zr.task.utils.EquipmentTypeUtils;
;import org.greenrobot.eventbus.EventBus;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class NetworkReceiver extends BroadcastReceiver {
    @RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE)
    @Override
    public void onReceive(Context context, Intent intent) {
        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
            ConnectivityManager manager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            if (manager == null) return;
            NetworkInfo activeNetwork = manager.getActiveNetworkInfo();

            if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
                EventBus.getDefault().post(404);
            }else{
                if (activeNetwork.isAvailable()) {
                    EventBus.getDefault().post(111);
                } else {
                    EventBus.getDefault().post(404);
                }
            }
        }
    }

}
